import axios from 'axios';
import query from 'query-string';

const BASE_URL = '/promotion/banner';


export interface BannerParam {
    type?: string;
    page?: number;
    size?: number;
    sort?: Array<string>;
}

export interface BannerResponse {
    id?: number;
    name: string;
    type?: string;
    bizId?: string;
    pic?: string;
    status?: string;
    clickCount?: string;
    url?: string;
    sort?: string;

    createdBy?: string;
    updatedBy?: string;
    createdAt?: string;
    updatedAt?: string;
}

export interface BannerSaveCommand {
    id?: number;
    name: string;
    type?: string;
    bizId?: string;
    pic?: string;
    status?: string;
    clickCount?: string;
    url?: string;
    sort?: string;
}

export interface BannerResponseList {
    list: BannerResponse[];
    total: number;
}


// 通过BannerParam参数获取分页列表
export function pageBanner(params: BannerParam) {
    return axios.get<BannerResponseList>(`${BASE_URL}/page`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    })
}

// 通过id获取轮播图信息
export function getBanner(id: number) {
    return axios.get<BannerResponse>(`${BASE_URL}/${id}`);
    
}

export function listBanner(params: BannerParam) {
    return axios.get<BannerResponse[]>(`${BASE_URL}/list`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    });
}


// 添加轮播图
export function addBanner(params: BannerSaveCommand) {
    return axios.post(`${BASE_URL}`, params);
}

// 更新轮播图
export function updateBanner(params: BannerSaveCommand) {
    return axios.put(`${BASE_URL}`, params);
}

// 批量删除轮播图
export function deleteBanner(ids: number | Array<number>) {
    return axios.delete(`${BASE_URL}/${ids}`);
}